<?php
$baseUrl = Yii::app()->request->baseUrl;
$extScript = Yii::app()->clientScript;
$extScript->registerCssFile($baseUrl . '/css/layout/master.css');

$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'master');
$this->breadcrumbs = array(
    Yii::t('home', 'master')
);

if (Yii::app()->user->isGuest || Yii::app()->user->id != SpecialUser::MASTER_ID) {
    $baseUrl = Yii::app()->getBaseUrl(true);
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'mydialog',
        // additional javascript options for the dialog plugin
        'options' => array(
            'title' => Yii::t('home', 'message'),
            'autoOpen' => true,
            'modal' => true,
            'beforeClose' => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=index";}',
            'buttons' => array(
                Yii::t('home', 'close') => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=login";}'
            ),
        ),
    ));

    echo Yii::t('home', 'require_login');

    $this->endWidget('zii.widgets.jui.CJuiDialog');
    return;
}

$baseUrl = Yii::app()->getBaseUrl(true);
$order_list = array();
if (!is_array($orders)) {
    array_push($order_list, $orders);
} else {
    $order_list = $orders;
}

if (count($order_list) == 0) {
    echo "No items";
    return;
}
?>
<div id="focus" class="wrapper row100 bgded" style="background-image:url('images/live-demo/background-03.jpg');">
    <div class="overlay">
        <div id="newsletter" class="clear">
            <h1><?= Yii::t('master', 'all_order') . " " . count($order_list) ?></h1>
            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'master-error-form',
                'enableClientValidation' => true,
                'clientOptions' => array(
                    'validateOnSubmit' => true,
                ),
                'htmlOptions' => array(
                    'enctype' => 'multipart/form-data'
                )
            ));
            ?>
            <div class="row" style="color: red;">
                <?php echo $form->error($model, 'throw_error'); ?>
            </div>
            <?php $this->endWidget(); ?>
            <fieldset>
                <?php
                $count = 0;
                foreach ($order_list as $order) {
                    ++$count;
                    
                    echo "เจ้าของ Order ::".$order->orderOwnerName;
                    ?>
                    <div class="master-box">

                        <div class="master-picture">
                            <?php if (isset($order->picture) && $order->picture != '') : ?>
                                <img src="<?= $baseUrl . '/' . $order->picture ?>" onclick="$('#picturedialog<?= $count ?>').dialog('open');
                                                return false;"/>
                                     <?php
                                     $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
                                         'id' => 'picturedialog' . $count,
                                         // additional javascript options for the dialog plugin
                                         'options' => array(
                                             'title' => Yii::t('home', 'picture'),
                                             'autoOpen' => false,
                                             'resizable' => false,
                                             'modal' => true,
                                             'width' => 'auto',
                                             'height' => 'auto'
                                         )
                                     ));

                                     $baseUrl = Yii::app()->getBaseUrl(true);
                                     echo '<img id="image" src="' . $baseUrl . '/' . $order->picture . '"/>';

                                     $this->endWidget('zii.widgets.jui.CJuiDialog');
                                 endif;
                                 ?>
                        </div>
                        <div class="master-content">
                            <ul class="master">
                                <li>
                                    <label><?= Yii::t('master', 'order_id') ?></label>
                                    <span><?= $order->order_id ?></span>
                                    <label><?= Yii::t('master', 'amount') ?></label>
                                    <span><?= $order->payment->amount ?></span>
                                    <label><?= Yii::t('master', 'order_date') ?></label>
                                    <span><?= ConvertFormatUtil::getDateLocale($order->create_date, Yii::app()->language) ?></span>
                                </li>
                                <li>
                                    <label><?= Yii::t('master', 'package') ?></label>
                                    <span><?= $order->package['package_name_' . Yii::app()->language] ?></span>
                                </li>
                                <?php
                                $options = ForetellTypeUtil::getForetellArrayType($order->option_type);
                                for ($i = 0; $i < count($options); $i++) {
                                    if ($i == 0) {
                                        echo "<li>
                                    <label>" . Yii::t('master', 'option_type') . "</label>
                                    <span>" . ($i + 1) . ". " . $options[$i] . "</span>
                                </li>";
                                    } else {
                                        echo "<li>
                                    <label>&nbsp;</label>
                                    <span>" . ($i + 1) . ". " . $options[$i] . "</span>
                                </li>";
                                    }
                                }
                                ?>

                                <li>
                                    <label><?= Yii::t('master', 'fullname') ?></label>
                                    <span><?= $order->name . ' ' . $order->surname ?></span>
                                </li>
                                <li>
                                    <label><?= Yii::t('master', 'birthday') ?></label>
                                    <span><?= ConvertFormatUtil::getThaiDateForMaster($order->birthdate) ?></span>
                                </li>
                                <li>
                                    <label><?= Yii::t('master', 'gender') ?></label>
                                    <span><?= ConvertFormatUtil::getFullGender($order->sex) ?></span>
                                </li>
                                <li>
                                    <label><?= Yii::t('master', 'mobilephone') ?></label>
                                    <span><?= $order->contact_tel ?></span>
                                </li>
                                <li>
                                    <label><?= Yii::t('master', 'remark') ?></label>
                                    <span><?= $order->remark ?></span>
                                </li>
                                <li>
                                    <label>&nbsp;</label>
                                    <div style="float:right">
                                        <?php echo CHtml::button(Yii::t('master', 'complete'), array('class' => 'btn', 'submit' => Yii::app()->createUrl("/master/confirm", array("id" => $order->order_id)), 'confirm' => Yii::t('master', 'confirm_order'), 'name' => 'complete' . $count)); ?>
                                    </div>
                                </li>
                                <li><label>&nbsp;</label></li>
                            </ul>
                        </div>
                    </div>
                    <br/>
                <?php } ?>
            </fieldset>
        </div>
    </div>
</div>